﻿@{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@section styles{
}
<div id="app" class="box box-primary">
    <div>
        <el-row type="flex" justify="center">
            <el-col v-bind:span="9">
                <h3 class="text-center text-success title">销售单</h3>
            </el-col>
        </el-row>
        <el-row>
            <el-col v-bind:span="8">销售单号：{{model.Code}}</el-col>
            <el-col v-bind:span="8">单据状态：{{model.StatusName}}</el-col>
            <el-col v-bind:span="8">制单日期：{{model.CreatedOnTime}}</el-col>
        </el-row>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>编码</th>
                    <th>名称</th>
                    <th>单价</th>
                    <th>数量</th>
                    <th>金额</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(item,index) in model.Items">
                    <td>{{index+1}}</td>
                    <td>{{item.ProductCode}}</td>
                    <td>{{item.ProductName}}</td>
                    <td>{{item.RealPrice}}</td>
                    <td>{{item.Quantity}}</td>
                    <td>{{item.Amount}}</td>
                </tr>
            </tbody>
            <tfoot>
                <tr>
                    <td></td>
                    <td>合计：</td>
                    <td></td>
                    <td></td>
                    <td>{{model.TotalQuantity}}</td>
                    <td>{{model.OrderAmount}}</td>
                </tr>
            </tfoot>
        </table>
        <el-row>
            <el-col v-bind:span="8">收货人：{{model.ReceiverName}}{{model.ReceiverTel}}</el-col>
            <el-col v-bind:span="8">收货地址：{{model.ReceiverFullAddress}}</el-col>
            <el-col v-bind:span="8">备注：{{model.Remark}}</el-col>
        </el-row>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        var demo = new Vue({
            el: '#app',
            data: {
                totalQuantity:"",
                lock: false,
                lockClearRow: false,
                StoreErrorMsg:"",
                model: @Html.Raw(ViewBag.SaleOrder)
            },
            methods: {
                //审核驳回
                rejectAudit: function (dialog, button,callback) {
                    var $this=this;
                    var data={ OrderCode: this.model.Code};
                    if(this.AuditedRemark=="")
                    {
                        this.$message.error('审核意见不能为空');
                        button.unlock();
                        return;
                    }
                    $.ajax({
                        type: 'post',
                        url: "/SaleOrder/Reject",
                        data: JSON.stringify(data),
                        dataType: "json",
                        contentType: 'application/json',
                        success: function (result) {
                            if (result.success) {
                                $this.$message.success({
                                    message:"驳回成功！",
                                    onClose:function(){
                                        button.unlock();
                                        dialog.close();
                                        if(callback)
                                        {
                                            callback();
                                        }
                                    }
                                });
                            }else {
                                button.unlock();
                                $this.$message.error(result.error);
                            }
                        }
                    });
                },
                //作废
                abandonSaleOrder: function (dialog, button, callback) {
                    var $this=this;
                    var data={ OrderCode: this.model.Code };
                    $.ajax({
                        type: 'post',
                        url: "/SaleOrder/AbandonSaleOrder",
                        data: JSON.stringify(data),
                        dataType: "json",
                        contentType: 'application/json',
                        success: function (result) {
                            if (result.success) {
                                $this.$message.success({
                                    message:"作废成功！",
                                    onClose:function(){
                                        button.unlock();
                                        dialog.close();
                                        if(callback)
                                        {
                                            callback();
                                        }
                                    }
                                });
                            }else {
                                button.unlock();
                                $this.$message.error(result.error);
                            }
                        }
                    });
                },
                //取消
                cancel:function(dialog, button, callback){
                    dialog.close();
                }
            },
            computed:{

            },
            created:function(){
                var dialog = window.parent.activeDialog;
                if (dialog) {
                    //dialog.bindEvent("passAudit",this.passAudit);
                //dialog.bindEvent("rejectAudit",this.rejectAudit);
                //dialog.bindEvent("abandonSaleOrder",this.abandonSaleOrder);
                dialog.bindEvent("cancel",this.cancel);
                // this.addRow();
                }

            }
        });
    </script>
}
